<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'
	xmlns:f='http://java.sun.com/jsf/core'
	xmlns:h='http://java.sun.com/jsf/html'
	xmlns:ui='http://java.sun.com/jsf/facelets'
	xmlns:p="http://primefaces.org/ui"> 
	<h:head>
	
	</h:head> 
	<h:body>
		<h:outputStylesheet name='css/main.css' />
		<p:dialog header="Enter schedules's data" widgetVar="scheduleDialog" resizable="false" modal="true">  
			<h:form id="createSchedules">  
		        <h:panelGrid columns="2" style="margin-bottom:10px">  
		            <h:outputLabel for="train" value="Train number:" />  
		            <p:autoComplete id="train" value="#{scheduleController.train}"  completeMethod="#{autoCompleteController.completeTrain}" dropdown="true"
		            forceSelection="true"  required = "true" />  
		   
		            <h:outputLabel for="station1" value="Station of departure:" />  
		            <p:autoComplete id="station1" value="#{scheduleController.station1}" completeMethod="#{autoCompleteController.completeStation}" dropdown="true"
		            forceSelection="true" required = "true" />  
		  
		            <h:outputLabel for="station2" value="Station of arrival:" />  
		            <p:autoComplete id="station2" value="#{scheduleController.station2}" completeMethod="#{autoCompleteController.completeStation}" dropdown="true"
		            forceSelection="true" required = "true"/>  
		       
		            <h:outputLabel for="departure" value="Date of departure:" />  
		            <p:calendar navigator="true" id="departure" value="#{scheduleController.schedule.dateOfDeparture}" pattern="yyyy-MM-dd HH:mm" required = "true" > 
						<f:convertDateTime pattern="yyyy-MM-dd HH:mm" />
					</p:calendar>   
 
		            <h:outputLabel for="arrival" value="Date of arrival:" />  
		            <p:calendar navigator="true" id="arrival" value="#{scheduleController.schedule.dateOfArrival}" pattern="yyyy-MM-dd HH:mm" required = "true" > 
						<f:convertDateTime pattern="yyyy-MM-dd HH:mm" />
					</p:calendar>  
		        </h:panelGrid> 
		        <p:commandButton id="submitButton" actionListener="#{scheduleController.createSchedule}" value="Create" update=":tabView:schedules" oncomplete="scheduleDialog.hide();"/>   
		   	</h:form>  
		</p:dialog>	
		<p:dialog header="Enter passengers's data" widgetVar="passengerDialog" resizable="false" modal="true">
				<h:form id="createPassengers">    
			        <h:panelGrid columns="2" style="margin-bottom:10px">  
			            <h:outputLabel for="passengerName" value="Name:" />  
			            <p:inputText id="passengerName" value="#{passengerController.passenger.passengerName}" required = "true">
			            	<f:validateLength minimum="2" maximum="15"/>
						</p:inputText>    
			   
			            <h:outputLabel for="passengerSurname" value="Surname:" />  
			            <p:inputText id="passengerSurname" value="#{passengerController.passenger.passengerSurname}" required = "true">
			           		<f:validateLength minimum="2" maximum="15"/>
						</p:inputText>    
			  
			            <h:outputLabel for="passengerDateOfBirth" value="Date of birth:" />  
			            <p:calendar id="passengerDateOfBirth" navigator="true" value="#{passengerController.passenger.passengerDateOfBirth}" pattern="yyyy-MM-dd" required = "true"> 
							<f:convertDateTime pattern="yyyy-MM-dd" />
						</p:calendar> 
			       
			            <h:outputLabel for="login" value="Login:" />  
			            <p:inputText id="login" value="#{passengerController.passenger.login}" required = "true" >
			           		<f:validateLength minimum="3" maximum="15"/>
						</p:inputText>       
	 
			            <h:outputLabel for="Password" value="Password:" />  
			            <p:inputText id="Password" value="#{passengerController.passenger.password}" required = "true" >
			           		<f:validateLength minimum="4" maximum="15"/>
						</p:inputText>      
			        </h:panelGrid> 
			        <p:commandButton id="submitButton" actionListener="#{passengerController.createPassenger}" value="Create" update=":tabView:passengers" oncomplete="passengerDialog.hide();"/>   
				</h:form>  				
		</p:dialog>
		<p:dialog header="Enter station's data" widgetVar="stationDialog" resizable="false"  modal="true">  
	        <h:form id="createStations">
		        <h:panelGrid columns="2" style="margin-bottom:10px">  
		            <h:outputLabel for="name" value="Station name:" />  
		            <p:inputText id="name" value="#{stationController.station.stationName}" required = "true" >
		            	<f:validateLength minimum="3" maximum="15"/>
					</p:inputText>    
		        </h:panelGrid>  
	        	<p:commandButton id="submitButton" actionListener="#{stationController.createStation}" value="Create" update=":tabView:stations" oncomplete="stationDialog.hide();"/> 
	        </h:form> 	  
		</p:dialog> 
		<p:dialog header="Enter train's data" widgetVar="trainDialog" resizable="false"  modal="true">  
	        	<h:form id="createTrains">  
		        	<h:panelGrid columns="2" style="margin-bottom:10px">  
			            <h:outputLabel for="trainNumber" value="Train number:" />  
			            <p:inputText id="trainNumber" value="#{trainController.train.trainNumber}" required ="true" >
			            	<f:validateLength minimum="2" maximum="15"/>
						</p:inputText>  
			            <h:outputLabel for="places" value="Train places:" />  
			            <p:inputText id="places" value="#{trainController.train.places}" required ="true" >
			            	<f:validateLength minimum="1" maximum="15"/>
						</p:inputText>  
		        	</h:panelGrid> 
		        	<p:commandButton id="submitButton" actionListener="#{trainController.createTrain}" value="Create" update=":tabView:trains" oncomplete="trainDialog.hide();"/>   
	        	</h:form>   
		</p:dialog>	
		
		
		<p:tabView id="tabView" dynamic="true" cache="true">  
		    <p:tab id="tab1" title="Train management"> 
		    	<h:form id="trains">
					<p:growl id="trainMessages" showDetail ="false" redisplay = "false" />
					<p:dataTable var="train" value="#{trainController.allTrains}"
						paginator="true" rows="10" id="trainList" rowKey="#{train.trainID}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15" editable="true" paginatorPosition="bottom">
						<p:column headerText="Train number" style="width:45%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{train.trainNumber}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{train.trainNumber}" style="width:100%" required = "true">
										<f:validateLength minimum="2" maximum="15"/>
									</p:inputText>
								</f:facet>
							</p:cellEditor>
						</p:column>
			
						<p:column headerText="Train number" style="width:45%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{train.places}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{train.places}" style="width:100%" required = "true"> 
										<f:validateLength minimum="1" maximum="15"/>
									</p:inputText>
								</f:facet>
							</p:cellEditor>
						</p:column>
			
						<p:column style="width:6%">
							<p:rowEditor icon="ui-icon-pencil" />
						</p:column>
						
						<p:column>
			           		<f:facet name="header">
			             		<h:outputText value="" />
			                </f:facet>
			                <p:commandButton icon="ui-icon-close" title="Remove train" update=":tabView:trains" actionListener="#{trainController.deleteTrain(train)}"/>          
			            </p:column>
			            <p:ajax event="rowEdit" listener="#{trainController.onEdit}"  update=":tabView:trains:trainMessages"/>
					</p:dataTable>		
					<p:commandButton id="showTrainCretaeDialog" type="button" value="Create" onclick="trainDialog.show()" />	 	
		    	</h:form>	 
		    </p:tab>  
		    <p:tab id="tab2" title="Station management">  
		    	<h:form id="stations">
					<p:growl id="stationsMessages" redisplay = "false" />
					<p:dataTable var="station" value="#{stationController.allStations}"
						paginator="true" rows="10" id="stationList" rowKey="#{station.stationID}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15" editable="true" paginatorPosition="bottom">
			
						<p:column headerText="Station name" style="width:90%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{station.stationName}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{station.stationName}" style="width:100%" required = "true">
										<f:validateLength minimum="3" maximum="25"/>
									</p:inputText>  
								</f:facet>
							</p:cellEditor>
						</p:column>
			
						<p:ajax event="rowEdit" listener="#{stationController.onEdit}" update=":tabView:stations:stationsMessages"/>
			
						<p:column style="width:6%">
							<p:rowEditor icon="ui-icon-pencil" />
						</p:column>
						
						<p:column>
			           		<f:facet name="header">
			             		<h:outputText value="" />
			                </f:facet>
			                <p:commandButton icon="ui-icon-close" title="Remove station" update=":tabView:stations" actionListener="#{stationController.deleteStation(station)}"/>          
			            </p:column>
					</p:dataTable>
					<p:commandButton id="showStationCreateDialog" type="button" value="Create" onclick="stationDialog.show()" />			 		 	
		    	</h:form>    
		    </p:tab>  
		    <p:tab id="tab3" title="Passenger management">  
		    	<h:form id="passengers">
					<p:growl id="passengersMessages" redisplay = "false" />
					<p:dataTable var="passenger" value="#{passengerController.allPassengers}"
						paginator="true" rows="10" id="passengerList" rowKey="#{passenger.passengerID}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15" editable="true" paginatorPosition="bottom">
			
						<p:column headerText="Name" style="width:18%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{passenger.passengerName}"/>
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{passenger.passengerName}" style="width:100%" required = "true">
										<f:validateLength minimum="2" maximum="15"/>
									</p:inputText>   
								</f:facet>
							</p:cellEditor>
						</p:column>
						
						<p:column headerText="Surname" style="width:18%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{passenger.passengerSurname}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{passenger.passengerSurname}" style="width:100%" required = "true">
										<f:validateLength minimum="2" maximum="15"/>
									</p:inputText>   
								</f:facet>
							</p:cellEditor>
						</p:column>
						
						<p:column headerText="Date of birth" style="width:18%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{passenger.passengerDateOfBirth}" />
								</f:facet>
								<f:facet name="input">
									<p:calendar navigator="true" value="#{passenger.passengerDateOfBirth}" style="width:100%" pattern="yyyy-MM-dd" required = "true"> 
										<f:convertDateTime pattern="yyyy-MM-dd" />
									</p:calendar>
								</f:facet>
							</p:cellEditor>
						</p:column>
						
						<p:column headerText="Login" style="width:18%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{passenger.login}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{passenger.login}" style="width:100%" required = "true">
										<f:validateLength minimum="3" maximum="15"/>
									</p:inputText>  
								</f:facet>
							</p:cellEditor>
						</p:column>
						
						<p:column headerText="Password" style="width:18%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{passenger.password}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{passenger.password}" style="width:100%" required = "true">
										<f:validateLength minimum="3" maximum="15"/>
									</p:inputText>  
								</f:facet>
							</p:cellEditor>
						</p:column>
			
						<p:ajax event="rowEdit" listener="#{passengerController.onEdit}" update=":tabView:passengers:passengersMessages"/>
						
						<p:column>
							<p:rowEditor icon="ui-icon-pencil" />
						</p:column>
						<p:column>
			           		<f:facet name="header">
			             		<h:outputText value="" />
			                </f:facet>
			                <p:commandButton icon="ui-icon-close" title="Remove passenger" update=":tabView:passengers" actionListener="#{passengerController.deletePassenger(passenger)}"/>          
			            </p:column>
					</p:dataTable>
					<p:commandButton id="showCretaeDialog" type="button" value="Create" onclick="passengerDialog.show()" />			 		 	
		    	</h:form>
		    </p:tab>
		     <p:tab id="tab4" title="Schedule management">  
		    	<h:form id="schedules">
					<p:growl id="schedulesMessages" redisplay = "false" />
					<p:dataTable var="schedule" value="#{scheduleController.allSchedules}"
						paginator="true" rows="10" id="scheduleList" rowKey="#{schedule.scheduleID}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15" editable="true" paginatorPosition="bottom">
						<p:column headerText="Schedule number" style="width:15%">
							<h:outputText value="#{schedule.scheduleID}" />
						</p:column>
						<p:column headerText="Train number" style="width:15%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{schedule.train.trainNumber}" />
								</f:facet>
								<f:facet name="input">
									<p:autoComplete value="#{schedule.train.trainNumber}" completeMethod="#{autoCompleteController.completeTrain}" dropdown="true"
					            		forceSelection="true" required = "true" /> 
								</f:facet>
							</p:cellEditor>
						</p:column>
						
						<p:column headerText="Station of departure" style="width:15%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{schedule.station1.stationName}" />
								</f:facet>
								<f:facet name="input">
									<p:autoComplete value="#{schedule.station1.stationName}" completeMethod="#{autoCompleteController.completeStation}" dropdown="true"
					            		forceSelection="true" required = "true" />  
								</f:facet>
							</p:cellEditor>
						</p:column>
						
						<p:column headerText="Station of arrival" style="width:15%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{schedule.station2.stationName}" />
								</f:facet>
								<f:facet name="input">
									<p:autoComplete value="#{schedule.station2.stationName}" completeMethod="#{autoCompleteController.completeStation}" dropdown="true"
					            		forceSelection="true" required = "true" />  
								</f:facet>
							</p:cellEditor>
						</p:column>
						
						<p:column headerText="Date of departure" style="width:15%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{schedule.dateOfDeparture}" > 
										<f:convertDateTime pattern="yyyy-MM-dd HH:mm" />
									</h:outputText>
								</f:facet>
								<f:facet name="input">
									<p:calendar navigator="true" value="#{schedule.dateOfDeparture}" pattern="yyyy-MM-dd HH:mm" required = "true" > 
										<f:convertDateTime pattern="yyyy-MM-dd HH:mm" />
									</p:calendar>
								</f:facet>
							</p:cellEditor>
						</p:column>
						<p:column headerText="Date of arrival" style="width:15%">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{schedule.dateOfArrival}"> 
										<f:convertDateTime pattern="yyyy-MM-dd HH:mm" />
									</h:outputText>
								</f:facet>
								<f:facet name="input">
									<p:calendar navigator="true" value="#{schedule.dateOfArrival}" pattern="yyyy-MM-dd HH:mm" required = "true" > 
										<f:convertDateTime pattern="yyyy-MM-dd HH:mm" />
									</p:calendar>
								</f:facet>
							</p:cellEditor>
						</p:column>
			
						<p:ajax event="rowEdit" listener="#{scheduleController.onEdit}" update=":tabView:schedules:schedulesMessages"/>
						<p:column>
							<p:rowEditor icon="ui-icon-pencil" />
						</p:column>		
						<p:column>
			           		<f:facet name="header">
			             		<h:outputText value="" />
			                </f:facet>
			                <p:commandButton icon="ui-icon-close" title="Remove schedule" update=":tabView:schedules" actionListener="#{scheduleController.deleteSchedule(schedule)}"/>          
			            </p:column>
					</p:dataTable>
					<p:commandButton id="showCretaeDialog" type="button" value="Create" onclick="scheduleDialog.show()" />
		    	</h:form>			 		 	   
		    </p:tab>    		   
		</p:tabView>	       
	</h:body> 
</html>
